package com.jic.member.controller.power;


import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.common.util.BeanUtil;
import com.jic.member.entity.power.MememberTypeGrade;
import com.jic.member.request.power.MememberTypeGradeRequest;
import com.jic.member.response.power.MememberTypeGradeResponse;
import com.jic.member.service.power.MememberTypeGradeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@ApiOperation(value = "会员类型等级controller")
@RestController
@RequestMapping("/meTypeGrade")
@Slf4j
public class MememberTypeGradeController {

    @Autowired
    MememberTypeGradeService megradeRule;

    /*
     * 分页查询
     * */
    @ApiOperation(value = "获取会员类型等级所有列表")
    @ResponseBody
    @RequestMapping("/queryMememberTypeGradeList")
    public RestResult<PageResult<MememberTypeGradeResponse>> queryMegradeRuleList(@RequestBody MememberTypeGradeRequest form) {
        log.info("开始进入等级权益关联列表=========》,{}", form.toString());
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        MememberTypeGrade memberRequest = BeanUtil.copy(form, MememberTypeGrade.class);
        PageResult<MememberTypeGrade> result = megradeRule.queryPage(memberRequest, page);
        List<MememberTypeGradeResponse> memberResponseList = result.getRows().stream().map(temp -> {
            MememberTypeGradeResponse memberResponse = BeanUtil.copy(temp, MememberTypeGradeResponse.class);
            return memberResponse;
        }).filter(item -> item != null).collect(Collectors.toList());

        PageResult<MememberTypeGradeResponse> pageResult = new PageResult<>();
        pageResult.setRows(memberResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);
    }
}
